using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_SanPham_DanhSachPhuongThucThanhToan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    #region"LoadData"
    private void LoadData()
    {
        pager.PageSize = 5;
        Criteria c = new Criteria();
        if (txt_TenPT.Text != "")
        {
            c.add(Condition.AND, tbPhuongThucThanhToanColumns.TenPT, Condition.LIKE,
                txt_TenPT.Text);
        }


        int total = 0;
        tbPhuongThucThanhToanCollection phuongThucCollection = tbPhuongThucThanhToanBUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
            tbPhuongThucThanhToanColumns.MaPT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = phuongThucCollection;
        Repeater1.DataBind();
        pager.ItemCount = total;

        pager.ItemCount = total;
        if (total <= pager.PageSize)
            pager.Visible = false;

    }
    #endregion
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
          e.Item.ItemType == ListItemType.Item)
        {
            tbPhuongThucThanhToan phuongThuc = (tbPhuongThucThanhToan)e.Item.DataItem;
            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "~/Admin/SanPham/CapNhatPhuongThucThanhToan.aspx?id=" + phuongThuc.MaPT.ToString();
        }
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoadData();
    }
    protected void lbt_Xoa_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_Xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbPhuongThucThanhToanBUS.Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
}
